import requests
from bs4 import BeautifulSoup


ls = []
def request(pages):
    url = "http://scxk.nmpa.gov.cn:81/xk/itownet/portalAction.do?method=getXkzsList"
    header = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebtKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3775.400 QQBrowser/10.6.4208.400'
    }
    for page in range(pages):
        data = {
            "on": "true",
            "page": page,
            "pageSize": 15,
            "productName": "",
            "conditionType": 1,
            "applyname": "",
            "applysn": ""
        }
        response = requests.post(url, data, headers=header)
        page_text = response.json()['list']
        for tmp in page_text:
            dc = {}
            dc["企业名称"] = tmp['EPS_NAME']
            dc["许可证编码"] = tmp['PRODUCT_SN']
            dc["发证机关"] = tmp['QF_MANAGER_NAME']
            dc["发证日期"] = tmp['XC_DATE']
            ls.append(dc);

#request(1)
def print_page():
    print("{0:^40}{1:^40}{2:^40}{3:^40}".format("企业名称","许可证编码","发证机关","发证日期"))
    for l in ls:
        print("{0[企业名称]:^40}{0[许可证编码]:^40}{0[发证机关]:^40}{0[发证日期]:^40}".format(l))

def main():
    pages= eval(input("请输入你要获取的页数:"))
    request(pages)
    print_page()
main()






